package com.mali.mq.producer;

import com.mali.mq.constant.MqConstants;
import com.mali.mq.domain.po.BizLog;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@RequiredArgsConstructor
public class LogProducer {

    private final RabbitTemplate rabbitTemplate;
    @PostConstruct
    public void init() {
        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
    }

    public void sendLog(BizLog log) {
        rabbitTemplate.convertAndSend(
                MqConstants.LOG_EXCHANGE,
                MqConstants.LOG_ROUTING_KEY,
                log
        );
    }
}
